Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

insert-rule

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insert-rule

Insert rules into a stylesheet programatically with a simple API

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
increased by101.54%
Maintainers
1
Weekly downloads
 
Created
Source

insert-rule

Insert rules into a stylesheet programatically with a simple API

Install

Using Bower

bower install -S insert-rule

Using npm

npm install -S insert-rule

insertRule(selector, styles)

Applies the styles to the selector. The selector can be any CSS selector. That includes :after and :before, too. Styles can either be plain text or an object. Keys in camelCase get converted into css-case.

Example
insertRule('body:after', 'font-weight: bold;');
insertRule('body:after', {
  content: '"Ha-ha!"',
  display: 'block',
  fontSize: '16px'
});

You can also remove all of the previously inserted rules.

insertRule.clear()

Only those inserted by the insert-rule module will be affected.

insertRule.remove(selector)

Removes style rules that were created using exactly the provided selector.

insertRule.context(name)

You can create a "context" that's self-contained, where rules will be added to a different style element. In this case, clear() removes all of the rules in the given context, and .remove(selector) only removes those rules matching the selector from the current context.

var foo = insertRule.context('foo');
var bar = insertRule.context('bar');
foo('#foo', 'color:#f00');
bar.remove('#foo'); // nothing happens
foo.remove('#foo'); // rule gets removed!

This separation of concerns is most useful when using insert-rule in "small-module" type environments.

Example
insertRule.clear();

License

MIT

FAQs

Package last updated on 14 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc